package com.tarena.lbs.activity.dao.repository.impl;

import com.tarena.lbs.activity.dao.mapper.ActivityMapper;
import com.tarena.lbs.activity.dao.repository.ActivityRepository;
import com.tarena.lbs.activity.pojo.po.ActivityPO;
import com.tarena.lbs.activity.pojo.vo.ActivityVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.tarena.lbs.base.protocol.model.Result;

import java.util.List;
import java.util.Optional;

@Slf4j
@Repository
public class ActivityRepositoryImpl implements ActivityRepository {
    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public List<ActivityVO> selectByBusinessId(Long businessId) {
        List<ActivityVO> list=activityMapper.selectByBusinessId(businessId);
        return list;
    }

    @Override
    public Result<ActivityVO> selectById(Long id) {
      ActivityPO activityPO=  activityMapper.selectById(id);
        ActivityVO activityVO = new ActivityVO();
        BeanUtils.copyProperties(activityPO,activityVO);
        return new Result<ActivityVO>(activityVO);
    }

    @Override
    public void insert(ActivityPO activityPO) {
        activityMapper.insert(activityPO);
    }

    /**
     * 根据id查询活动
     * @author heyu
     * @param activityId
     * @return ActivityPO
     */
    @Override
    public ActivityPO findById(Integer activityId) {
        return activityMapper.selectById(activityId);
    }
}
